# 会议视频文字自动记录系统 Dockerfile
FROM python:3.9-slim

# 设置工作目录
WORKDIR /app

# 设置环境变量
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive

# 安装系统依赖
RUN apt-get update && apt-get install -y \
    # OpenCV依赖
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgomp1 \
    libglib2.0-0 \
    libgtk-3-0 \
    # 图像处理依赖
    libgl1-mesa-glx \
    libglib2.0-0 \
    # FFmpeg依赖
    ffmpeg \
    # 其他工具
    wget \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# 安装OpenVINO运行时
RUN pip install openvino-dev[onnx]==2023.2.0

# 复制requirements文件
COPY requirements.txt .

# 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt

# 创建必要的目录
RUN mkdir -p /app/data \
    /app/logs \
    /app/models \
    /app/temp \
    /app/exports \
    /app/uploads \
    /app/config

# 复制应用代码
COPY src/ ./src/
COPY config/ ./config/

# 复制启动脚本
COPY scripts/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

# 创建非root用户
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser

# 暴露端口
EXPOSE 8000

# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# 启动命令
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["python", "-m", "src.main"]
